<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/gsap.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/ScrollTrigger.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/TextPlugin.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        body {
            width: 100vw;
            overflow-x: hidden;
        }
        .box1 {
            height: 100vh;
            /* background-color: #eee; */
            display: flex;
            align-items: center;
            justify-content: stretch;
        }
        .bg-lines__group {
            height: 100vh;
        }
        .bg-lines__box {
            --box-color: #aaa;
            --box-h: 20vh;
            width: 100vw;
            min-height: 20vh;
            position: relative;
            transform: translateX(100%);
        }
        .n-1 {
            --box-color: #eee;
        }
        .n-2 {
            --box-color: #ddd;
        }
        .n-3 {
            --box-color: #ccc;
        }
        .n-4 {
            --box-color: #bbb;
        }
        .n-5 {
            --box-color: #aaa;
        }
        .bg-lines__box > div {
            background: var(--box-color);
            min-height: var(--box-h);
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="box1"></div>
        <div class="bg-lines__group">
            <div class="bg-lines__box n-1"><div class="box-1"></div></div>
            <div class="bg-lines__box n-2"><div class="box-2"></div></div>
            <div class="bg-lines__box n-3"><div class="box-3"></div></div>
            <div class="bg-lines__box n-4"><div class="box-4"></div></div>
            <div class="bg-lines__box n-5"><div class="box-5"></div></div>
        </div>
        <div class="box1"></div>
        
        
      </div>

    <!-- <button id="animate">animate</button> -->
    <script>
        // use a script tag or an external JS file
        document.addEventListener("DOMContentLoaded", (event) => {
            gsap.registerPlugin(ScrollTrigger,TextPlugin)
            
            // let timeline1 = gsap.timeline({
            //     scrollTrigger: {
            //         trigger: ".wrapper",
            //         scrub: .5,
            //         start: "top 80%",
            //         end: "30%",
            //         pin: false,
            //         markers: true
            //     }
            // })
            // timeline1
            //     .to('.bg-lines__box:nth-child(1)', {x: '0'})
            //     .to('.bg-lines__box:nth-child(2)', {x: '0'}, 1)
            //     .to('.bg-lines__box:nth-child(3)', {x: '0'}, 2)


            // 使用querySelectorAll获取所有.bg-lines__box元素
            const boxes = document.querySelectorAll('.bg-lines__box');

            // 使用forEach迭代每个元素
            boxes.forEach(box => {
                gsap.to(box, {
                    x: '0',
                    scrollTrigger: {
                        trigger: box,
                        scrub: .5,
                        start: "top 94%",
                        end: "bottom 100%",
                        markers: true
                    }
                });
            });
        });
       
       </script>
</body>
</html>